package view.ui.minimap
{
	import control.manager.BitmapManager;
	import control.manager.LayerManager;
	import control.manager.MapManager;
	
	import data.MapData;
	
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	
	import ghostcat.display.transfer.MiniMap;
	
	import view.Immortal;
	import view.item.MapTileItem;
	import view.layer.GameLayer;
	import view.stage.StageGame;
	
	public class UIMiniMap extends Sprite
	{
		private const NAME :String = "mainUI_miniMapUI";
		
		/**
		 * 按钮层 
		 */		
		public var btnLayer :MovieClip;
		/**
		 * 场景名称文本 
		 */		
		public var sceneNameTxt :TextField;
		/**
		 * 场景人物的位置 
		 */		
		public var sceneXYTxt :TextField;
		/**
		 * 全屏按钮 
		 */		
		private var btnFull :SimpleButton;
		public function UIMiniMap()
		{
			super();
			init();
		}
		private function init():void
		{
			if(ApplicationDomain.currentDomain.hasDefinition(NAME))
			{
				var cls :Class = getDefinitionByName(NAME) as Class;
				var mc :MovieClip = new cls() as MovieClip;
				addChild(mc);
				
				this.btnLayer = mc.btnLayer;
				this.btnFull = this.btnLayer.btnFull;
				
				
				this.sceneNameTxt = this.btnLayer.sceneNameTxt;
				this.sceneXYTxt = this.btnLayer.sceneXYTxt;
				
				var mapData :MapData = MapManager.instance.curMapData;
				var gamelayer :GameLayer = LayerManager.instance.getLayer(GameLayer.NAME) as GameLayer;
				if(mapData && gamelayer)
				{
					this.sceneNameTxt.text = mapData.mapName;
					this.sceneXYTxt.text = int(gamelayer.player.x) + "." + int(gamelayer.player.y);
				}
				
				addEventListener(MouseEvent.MOUSE_UP,mouseHandler);
			}
		}
		
		private function mouseHandler(e :MouseEvent):void
		{
			switch(e.target)
			{
				case this.btnFull:
					var gameLayer :GameLayer = LayerManager.instance.getLayer(GameLayer.NAME) as GameLayer;
					
					
					if(Immortal.instance.curStage is StageGame)
					{
						var stageGame :StageGame = Immortal.instance.curStage as StageGame;
						stageGame.full(true);
					}
					break;
			}
		}
	}
}